<!DOCTYPE html>
<html>
<head>
  <title>上传文件</title>
  <meta charset="UTF-8">
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" id="uploadForm">
  <label for="fileInput">选择要上传的文件:</label>
  <input type="file" name="fileInput" id="fileInput"><br><br>
  <input type="submit" value="上传" id="tdkd">TDK+描述</br></br></br></br>
  <input type="submit" value="上传" id="tdk">TDK
</form>

<script>
  // $(document).ready(function() {
  //   $('#uploadForm').submit(function(event) {
  //     event.preventDefault();
  //
  //     var formData = new FormData($(this)[0]);
  //
  //     $.ajax({
  //       url: '/index.php?s=excel&c=excel&m=read',
  //       type: 'POST',
  //       data: formData,
  //       processData: false,
  //       contentType: false,
  //       success: function(response) {
  //         alert('文件上传成功！');
  //       },
  //       error: function(xhr, status, error) {
  //         alert('文件上传失败：' + error);
  //       }
  //     });
  //   });
  // });
  $(document).ready(function() {
    $('#tdkd').click(function(event) {
      event.preventDefault();

      var formData = new FormData($('#uploadForm')[0]);
      formData.append('type', 'tdkd');

      $.ajax({
        url: '/index.php?s=excel&c=excel&m=read',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,
        success: function(response) {
          alert('文件上传成功！');
        },
        error: function(xhr, status, error) {
          alert('文件上传失败：' + error);
        }
      });
    });

    $('#tdk').click(function(event) {
      event.preventDefault();

      var formData = new FormData($('#uploadForm')[0]);
      formData.append('type', 'tdk');

      $.ajax({
        url: '/index.php?s=excel&c=excel&m=read',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,
        success: function(response) {
          alert('文件上传成功！');
        },
        error: function(xhr, status, error) {
          alert('文件上传失败：' + error);
        }
      });
    });
  });
</script>
</body>
</html>